<template>
  <div class="activity">
    <div class="tabs">
      <div
        class="tab-item"
        v-for="(item, index) of tabs"
        :key="index"
        @click="tabItemClick(index)"
        :class="{'active': activeIndex === index}"
      >{{item}}</div>
      <div class="tab-angle" :style="{left: anLeft +'rem'}">
        <img src="@/assets/images/icon_sjb.png" alt />
      </div>
    </div>
    <Scroll class="act-scroll" v-if="activityList.length">
      <div class="content">
        <div class="inner">
          <div v-for="(item, index) of activityList" :key="index" class="panel-item">
            <panel-item-act
              :panelInfo="item"
              @click.native="$router.push({name: 'MyActivityDetail', params: {id: item.id}, query: {showBtn: false}})"
            />
          </div>
        </div>
      </div>
    </Scroll>
    <no-result v-else :src="require('@/assets/images/1-zwnr.png')" msg="暂无内容" />
    <transition name="slide">
      <router-view></router-view>
    </transition>
  </div>
</template>
<script>
import Scroll from '@/components/scroll/scroll'
import NoResult from '@/components/no-result/no-result'
import PanelItemAct from '@/components/panel-item-act'
import { getMyActivity } from '@/api/my'
const ERR_OK = 200
export default {
  components: {
    Scroll,
    NoResult,
    PanelItemAct
  },
  data () {
    return {
      tabs: ['已报名', '已签到'],
      activeIndex: 0,
      anLeft: 0.7,
      activityList: [],
      status: 0
    }
  },
  created () {
    this._getMyActivity(this.status)
  },
  methods: {
    tabItemClick (index) {
      this.activeIndex = index
      switch (index) {
        case 0:
          this.anLeft = 0.7
          this.status = 0
          break
        case 1:
          this.status = 1
          this.anLeft = 2.25
          break
      }
      this._getMyActivity(this.status)
    },
    _getMyActivity (status) {
      getMyActivity(status)
        .then(res => {
          if (res.code === ERR_OK) {
            console.log(res)
            this.activityList = res.data
          }
        })
        .catch(err => {
          console.log(err)
        })
    }
  }
}
</script>
<style lang="scss" scoped>
@import "@/styles/mixin.scss";
@include slideEnter();
.activity {
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background: #f7f7f7;
  z-index: 8;
  touch-action: none;
  .act-scroll {
    position: absolute;
    top: 1rem;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    box-sizing: border-box;
  }
  .tabs {
    width: 100%;
    height: 1rem;
    background: rgba(255, 255, 255, 1);
    padding: 0 0.36rem;
    box-sizing: border-box;
    display: flex;
    justify-content: flex-start;
    position: relative;
    .tab-item {
      font-size: 0.28rem;
      line-height: 0.28rem;
      font-family: PingFang SC;
      font-weight: 300;
      color: rgba(51, 51, 51, 1);
      text-align: center;
      margin-right: 0.71rem;
      padding: 0.36rem 0;
      &.active {
        font-weight: bold;
      }
    }
    .tab-angle {
      position: absolute;
      bottom: 0;
      width: 0.12rem;
      height: 0.06rem;
      transition: all 0.15s;
      img {
        width: 100%;
        vertical-align: top;
      }
    }
  }
  .content {
    width: 100%;
    padding: 0.43rem 0.36rem 0 0.36rem;
    box-sizing: border-box;
    .inner {
      width: 100%;
      height: 100%;
      padding-bottom: 2rem;
    }
    .panel-item {
      margin-bottom: 0.41rem;
      &:last-of-type {
        margin-bottom: 0;
      }
    }
  }
}
</style>
